// pages/zxbx/zxbx.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    houseId: "",
    house: "",
    repairItemId: "",
    repairItem: "",
    appointment: "",
    gender: "",
    description: "",
    show: false,
    mobile: "",
    show2: false,
    attachment: [],
    show1: false,
    actions1: [],
    actions: [],
    currentDate: new Date().getTime(),
    minDate: new Date().getTime(),
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`;
      }
      if (type === 'month') {
        return `${value}月`;
      }
      return value;
    },

  },
  onInput(e) {
    console.log(e)
  },
  afterRead(e) {
    console.log(e)
    wx.uploadFile({
      url: wx.http.baseURL + '/upload',
      filePath: e.detail.file.url,
      name: 'file',
      header: {
        Authorization: app.token
      },
      formData: {

      },
      success: (res) => {
        console.log(res)
        const data = JSON.parse(res.data);
        console.log(data)


        this.data.attachment.push({
          ...data.data
        });
        this.setData({
          attachment: this.data.attachment
        })
      }
    })
  },
  onconfirm(e) {
    console.log(e)
    const date = new Date(e.detail)
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    console.log(year, month, day)
    this.setData({
      visitDate: year + "-" + month + "-" + day,
      show2: false
    })
  },
  async addfw() {
    const res = await wx.http({
      url: "/visitor",
      method: "post",
      data: {
        houseId: this.data.houseId,
        name: this.data.name,
        gender:this.data.gender,
        mobile: this.data.mobile,
        visitDate: this.data.visitDate,

      }
    })
    if (res.code == 10000) {
      wx.showToast({
        title: '提交成功',
        icon: "none"
      })
      wx.navigateTo({
        url: '/pages/wdfk/wdfk',
      })
    } else {
      wx.showToast({
        title: '请检查',
        icon: "none"
      })
    }
  },
  xzsj() {
    this.setData({
      show2: true
    })
  },
  onClose() {
    this.setData({
      show: false
    })
  },
  onClose1() {
    this.setData({
      show1: false
    })

  },
  onClose2() {
    this.setData({
      show2: false
    })

  },
  onSelect(e) {
    console.log(e)
    this.setData({
      houseId: e.detail.id,
      house: e.detail.name,
    })
  },
  onSelect1(e) {
    console.log(e)
    this.setData({
      repairItemId: e.detail.id,
      repairItem: e.detail.name,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getfw()
    this.getfw1()
  },
  xzfw() {
    this.setData({
      show: true
    })
  },
  xzfw1() {
    this.setData({
      show1: true
    })
  },
  async getfw() {
    const res = await wx.http({
      url: "/house"
    })
    console.log(res)
    this.setData({
      actions: res.data
    })
  },
  async getfw1() {
    const res = await wx.http({
      url: "/repairItem"
    })
    console.log(res)
    this.setData({
      actions1: res.data
    })
  },
  onChange() {

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})